package com.firesrc.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.firesrc.bean.Config;
import com.firesrc.service.ConfigService;
import com.firesrc.service.impl.ConfigServiceImpl;

public class S {
	private static Map<String, String> map;

	/**
	 * 通过key得到字符串值
	 * @param key
	 * @return
	 */
	public static String v(String key) {
		if (map == null) {
			map = initMap();
		}
		return map.get(key);

	}

	public synchronized static Map<String, String> initMap() {
		map = new HashMap<String, String>();
		ConfigService service = new ConfigServiceImpl();
		List<Config> allList = service.getAllList();
		for (Config config : allList) {
			map.put(config.getName(), config.getValue());
		}
		return map;
	}

	/**
	 * 通过key得到int类型的值
	 * @param key
	 * @return
	 */
	public static int i(String key) {
		String string = v(key);
		return Integer.parseInt(string);
	}
}
